home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / prog_disc / volume_3 / issue01 / testtail < prev   
Encoding:
Text File  |  1989-09-17  |  1.8 KB  |  60 lines

  1. {>Pas.testtail }
  2. program testtail(output);
  3. { Program with PROCEDURE to read the command line
  4.   Author I M Smith  April 11th 1989 }
  5.  
  6. const
  7.    stringlength = 255;
  8.  
  9. type
  10.    strings = packed array[1..stringlength] of char;
  11.  
  12. var
  13.    command  :  strings;
  14.  
  15. procedure getcommandline (var command : strings);
  16. const
  17.    r0 = 0;                      { Register 0 }
  18.    r4 = 4;                      { Register 4 }
  19.    OS_GetEnv = 16_10;           { SWI number }
  20.  
  21. type
  22.    stringptr = ^strings;
  23.  
  24. var
  25.    sptr   : stringptr;
  26.    a0,i   : integer;
  27.  
  28. begin
  29.    a0 := address(sptr);        { sptr can hold the address of a string }
  30.    *LDR_R4,a0;                 { Load register 4 with address of sptr  }
  31.    *SWI_OS_GetEnv;             { Call the SWI to read the command tail }
  32.    *STR_R0,[R4];               { Store the contents of R0, which is the
  33.                                  address of the command tail string, in the
  34.                                  location whose address is in R4. R4 contains
  35.                                  the address of sptr. SO sptr contains the
  36.                                  address of the command tail string }
  37.  
  38.    command := sptr^;           { This copies the string pointed to by sptr }
  39.  
  40.    i       := 1;               { This finds the terminator CHR(0) }
  41.    while command[i] <> chr(0) do
  42.       i := i+1;
  43.    while i < stringlength do   { Pad the rest of the string with ' ' }
  44.       begin
  45.          i := i+1;
  46.          command[i] := ' ';
  47.       end;
  48. end;
  49.  
  50. begin
  51.    getcommandline(command);
  52.    writeln(command)
  53.  
  54.    { You will need to add a call to a Pascal routine here to extract the
  55.      parameters from the command tail.  Something like GetParameter(Command,
  56.      n), where n is an integer, will do.  This will return a string and if
  57.      numbers, whether INTEGER or REAL are part of the tail, then you will
  58.      need to use conversion routines. }
  59. end.
  60.